<% @salles.each do |salle| %>
<% @machines = Machine.find_all_by_salle_id(salle.id, :order =>"ordre") %>
	<div class="ico_salle" id="table_salle_<%= salle.id %>">
	<div class="Salle_machine">
	<table class="table_salle" >
		<tr align="center">
			<% salle_id = "salle_#{salle.id}" %>
			<% if authenticated? %>
				<td>
				  	<span style="cursor:move" class="handle_salle"><%= image_tag('dnd-move-linux.png', :alt =>"move", :height =>"32px", :width =>"32px") %></span>
				</td>
			<% end %>
			<td>
				<%= link_to 'Afficher machines', '#', :id => 'lien_affichage_machine_'+salle.id.to_s, :onclick => "gererAffichageMachine("+salle.id.to_s+", true);" %>
			</td>
				<td>
					
			  	<div id="nom_<%= salle_id %>" class="nom_salle" <% if authenticated? %>style="cursor:move"<% end %>>
			  		<%= image_tag('building.png',:alt =>"Building", :height =>"16px", :width =>"16px") %><span id="nom_salle"><%=h salle.nom_salle %></span>
			  		<% if salle.id > 0 %>
						<% if Incident.getIncidentBySalle(salle.id) %>
							<%= link_to(image_tag('warning.png', :title => "Il y a un ou plusieurs accident(s) sur les machines de cette salle",:alt =>"incident", :height =>"16px", :width =>"16px" ), :controller => :salles, :action => 'show', :id => salle.id ) %>
						<% end %>
					<% end %>  		
			  	</div>
			</td>
			<td>	
				<%= link_to 'Voir', salle %>
				<% if authenticated? %>
		    		<%= link_to 'Modifier', edit_salle_path(salle) %>
		    		<%= link_to_remote 'Supprimer', 
		    			:url => {:controller => :salles, :action => :destroy}, 
		    			:with => "'id=#{salle.id}'", 
		    			:script => true,
		    			:before =>  "$('loading_delete_salle_salle_"+salle.id.to_s+"').show()",
		    			#:complete => "$('loading_delete_salle_"+salle_id.to_s+"').show()", 
		    			:confirm => 'Etes-vous sur de supprimer cette salle ?'%>
		    		<%= image_tag('loading.gif', :id => 'loading_delete_salle_'+salle_id.to_s, :style => "display:none", :alt =>"chargement", :height =>"16px", :width =>"16px")%>
		    	<% end %>
	    	</td>
		</tr>
	</table>
	<div class="scroll" id="scroll_machine_<%= salle.id %>" style="display:none;">
			<table >
				<tr>
					<td colspan="2">
						<div id="liste_machines_<%= salle.id %>">
							<%= render :partial => "machines/listMachine", :locals => { :machines => @machines, :salle_id => salle.id} %>
						</div>
					</td>
				</tr>
			</table>
	</div>
	<table>
		<tr>
			<td colspan="2">
				<% if authenticated? %>
					<div id="divLienAfficherMachine_<%= salle.id%>">
						<%= link_to_function 'Ajouter une machine', "$('divAjouterMachine_"+salle.id.to_s+"').show();$('divLienAfficherMachine_"+salle.id.to_s+"').hide()" %>
					</div>
				<% end %>
				<div id="divAjouterMachine_<%= salle.id%>" style="display:none;">
				<% remote_form_for :machine, 
					:url => {:action => 'create', :controller => 'machines'}, 
					#:update => "liste_machines_"+salle.id.to_s ,
					:before => "$('loading_create_machine_"+salle.id.to_s+"').show();gererAffichageMachine("+salle.id.to_s+",true);",
					:complete => "$('divAjouterMachine_"+salle.id.to_s+"').hide();$('divLienAfficherMachine_"+salle.id.to_s+"').show();$('loading_create_machine_"+salle.id.to_s+"').hide();$('new_machine_"+salle.id.to_s+"').elements['machine[nom_machine]'].value='';$('new_machine_"+salle.id.to_s+"').elements['machine[adresse_ip]'].value=''", 
					:html => { :id => "new_machine_"+salle.id.to_s, :name => "new_machine_"+salle.id.to_s  }, 
					:condition=>"validateFormMachine('"+salle.id.to_s+"')!=false" do |f| %>
					
				  <%= hidden_field_tag "machine[salle_id]", salle.id %>
				  <table class="ajoutMachine">
				  	<tr>
				  		<td><%= f.label "Nom" %></td>
				  		<td><%= f.text_field :nom_machine, :size => 15 %></td>
				  		<td><span id="error_nom_machine_<%= salle.id.to_s %>" style="color:red"></span></td>				  		
				  	</tr>
				  	<tr>
				  		<td><%= f.label "Adresse IP" %></td>
				  		<td><%= f.text_field :adresse_ip %></td>
				  		<td><span id="error_adresse_ip_<%= salle.id.to_s %>" style="color:red"></span></td>				  		
				  	</tr>
				  	<tr>
				  		<td>
				  			<%= submit_tag "Enregistrer "%>
				  			<%= image_tag('loading.gif', :id => 'loading_create_machine_'+salle.id.to_s, :style => "display:none", :alt =>"chargement", :height =>"16px", :width =>"16px")%>				  			
				  		</td>
				  		<td><%= link_to_function 'Annuler', "$('divAjouterMachine_"+salle.id.to_s+"').hide();$('divLienAfficherMachine_"+salle.id.to_s+"').show()" %></td>
				  	</tr>
				  </table>
				 <% end -%>
				</div>
			 </td> 
	  	</tr>
	  	<% if authenticated? %>
			<%= drop_receiving_element("table_salle_#{salle.id}",                             # The id of the receiving element
			  :accept => "machine",                                         # The CSS class of the dropped element
			  :with   => "'machine_id=' + (element.id.split('_').last())+'&salle_id=#{salle.id}'",     # The query string parameters
			  :url    => {:action=>:changeMachine, :controller => :machines}                          # The action to call
			)%>
			<%= draggable_element("nom_"+salle_id.to_s, :revert=>true, :ghosting => false, :change  => "function() { $('trash').show() }") %>
		<% end %>
	  </tr>
	</table>
</div>
</div>
<% end %>
<% if authenticated? %>
	<%= sortable_element('liste_salles', :tag => "div", :revert => true, :ghosting => false, :url=> {:controller=> "salles", :action=> "sort"}, :handle=> 'handle_salle' )%>
<% end %>
